﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
namespace TY_WinApp.Wrapper
{ 
   public class GcDev
    {
        ////图像获取回调函数
        //[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
        //unsafe public delegate void DelegateGcImageFun(IntPtr pParam);

        //获取设备数量
        //返回连接到电脑中的USB相机数量，如果为0表示无设备连接
        [DllImport("Lib/gcDev.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl, EntryPoint = "gcGetNumberDevices")]
        public static extern Byte  GcGetNumberDevices();

        //获取设备ID
        //nIndex in 从0开始索引
        //返回设备nID值，有效ID从1开始，0为无效ID
        [DllImport("Lib/gcDev.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl, EntryPoint = "gcGetDeviceID")]
        public static extern Byte GcGetDeviceID(Byte nIndex);

        //打开设备
        //nID in 为设备ID值，范围从1～32
        //成功返回true，失败返回false
        [DllImport("Lib/gcDev.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl, EntryPoint = "gcOpenDevice")]
        public static extern bool GcOpenDevice(Byte nIndex);

        //关闭设备
        //nID in 为设备ID值，范围从1～32
        //成功返回true，失败返回false
        [DllImport("Lib/gcDev.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl, EntryPoint = "gcCloseDevice")]
        public static extern bool GcCloseDevice(Byte nIndex);

        //设备是否已经打开
        //nID in 为设备ID值，范围从1～32
        //成功返回true，失败返回false
        [DllImport("Lib/gcDev.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl, EntryPoint = "gcIsOpen")]
        public static extern bool GcIsOpen(Byte nIndex);

        //启动图像采集
        //nID in 为设备ID值，范围从1～32
        //成功返回true，失败返回false
        [DllImport("Lib/gcDev.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl, EntryPoint = "gcStartAcquisition")]
        public static extern bool GcStartAcquisition(Byte nIndex);

        //停止图像采集
        //nID in 为设备ID值，范围从1～32
        //成功返回true，失败返回false
        [DllImport("Lib/gcDev.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl, EntryPoint = "gcStopAcquisition")]
        public static extern bool GcStopAcquisition(Byte nIndex);

        //获取一帧图像
        //nID in 为设备ID值，范围从1～32
        //pBuffer out 接收图像数据缓存，必须大于实际的图像缓存大小，最好再加1M字节以上，防止缓存溢出
        //TimeOut in 超时时间设置，以ms为单位
        //pParam out CBFUN_INFO结构体指针(gcParam.h)，不使用可以设置为NULL
        //返回实际有效的图像数据大小，以字节为单位
        //如果调用gcRegImageCbFun（）函数注册了回调函数，则该函数无效！
        [DllImport("Lib/gcDev.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl, EntryPoint = "gcGetImage")]
        public static extern int GcGetImage(Byte nIndex, IntPtr pBuffer,int timeOut,IntPtr pParam);

        ////注册回调函数Image
        ////nID in 为设备ID值，范围从1～32
        ////func in 回调函数
        ////pBuffer in 图像数据缓存地址指针，建议比实际图像大 1 MBytes
        ////pHandle in 用户自定义指针
        ////调用该函数后，gcGetImage（）函数自动无效！
        //[DllImport("Lib/gcDev.dll", CharSet = CharSet.Auto, CallingConvention = CallingConvention.Cdecl, EntryPoint = "gcRegImageCbFun")]
        //public static extern void GcRegImageCbFun(Byte nIndex, DelegateGcImageFun delegateGcImageFun, IntPtr pBuffer,IntPtr pHandle);
    }
}
